  export default {
    name: 'regionList',
    data() {
      return {
        cityList: [],
        addtoView: '',
				searchVal:'',
				type:null,
				nowCity:{name:'',id:''},
      }
    },
    
    filters: {
      // 过滤将letter的值Aa ，转为# 进行显示
      letter(str) {
        return str === 'Aa' ? '#' : str
      }
    },
    onLoad(options){
			this.type=options.type
			if(options.type==='1'){
				uni.setNavigationBarTitle({
				    title: '上牌地址'
				});
			}else if(options.type==='2'){
				uni.setNavigationBarTitle({
				    title: '区域要求'
				});
			}
			else if(options.type==='3'){
				uni.setNavigationBarTitle({
				    title: '车源所在地'
				});
			}
			else if(options.type==='4'){
				uni.setNavigationBarTitle({
				    title: '销售地区'
				});
			}
			this.nowCity.name=this.$store.state.city
		},
    methods: {
			search(){},
      //获取地址列表
      async getCityList() {
        try {
          const { data } = await this.$api.jsonData.regionalCityGroup()
          this.cityList = data.list.map(item => {
            // 将#号改成Aa
						item.data.forEach(it=>{
							if(it.name==this.nowCity.name){
								this.nowCity.id=it.id
							}
						})
            if (item.letter === '#') {
              return { ...item, letter: 'Aa' }
            } else {
              return item
            }
          })
        } catch (e) {
          console.log(e)
        }
      },
      
      // 点击选择了地区
      selected(city) {
				uni.$emit('selectCity',{type:this.type,value:city})
        uni.navigateBack()
      },
      
      // 地址字母索引定位
      addressToView(event) {
        let id = event.currentTarget.dataset.id
        this.addtoView = id
      },
      
      // 关闭当前列表
      close() {
        this.$emit('close')
      },
    },
    
    created() {
			
      this.getCityList()
			
    }
  }
